<extend name="Base/common"/>
<block name="body">
    <link href="__PUBLIC__/Home/css/show.css" rel="stylesheet">
    <div class="main-title text-center">
        <input type="text" class="hidden input-mini" name="bid" id="bid" value="{$order['id']}" readonly>
        <h2 style="font-size: 25px">{$order['name']}</h2>
    </div>
    <div class="container">
        <!--第一层节点-->
        <volist name="roots" id="first">
            <div class="checkmod">
                <div class="">
                    <h4>{$first['name']}</h4>
                </div>
                <div class="bd">
                    <notempty name="first['child']">
                        <!--第二层节点-->
                        <volist name="first['child']" id="second">
                            <div class="hd2 span12">
                                <div class="hd2_label"><label style="margin-left: 10px;">{$second['name']}:</label>
                                </div>
                                <notempty name="second['child']">
                                    <!--<span class="divsion"></span>-->
                                    <!--第三层节点-->
                                    <div class="">
                                        <span class="child_row">
                                            <foreach name="second['child']" item="third">
                                                <label class="" style="margin-left: 20px;">{$third['name']}
                                                    <input class="input-mini" name="ans_{$second['id']}"
                                                           groupid="{$second['id']}:{$third['id']}"
                                                           type="{$third['type']}" placeholder="{$third['remark']}"
                                                           value="">
                                                </label>
                                            </foreach>
                                        </span></div>
                                </notempty>
                            </div>
                        </volist>
                    </notempty>
                </div>
            </div>
        </volist>
        <div class="hd2 span12">
            <div class="hd2_label" style=" margin-bottom: 10px;">
                <label style="margin-left: 10px; font-size: 20px;">补充信息</label>
            </div>
            <div class="">
                    <span class="child_row">
                    <textarea id="more" type="text" name="more" style="width: 99%; height: 100px" ></textarea>
                </span>
            </div>
        </div>
    </div>

    <div class="line">
        <div class="span12">
            <div class="span1">姓名</div>
            <input id="username" type="text" name="username"></div>
        <div class="span12">
            <div class="span1">联系方式</div>
            <input id="phone" type="text" name="phone"></div>
    </div>
    <div class="hd_btn">
        <button class="btn btn-success submit-btn" id="user_submit">提交</button>
        <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
    </div>

    <script>
        $(function () {
            $('#user_submit').click(function () {
                var username = $('#username').val();
                var more = $('#more').val();
                var phone = $('#phone').val();
                var bid = $('#bid').val();
                var elements = $("input[name^='ans']");
                var answers = [];
                for (var i = 0; i < elements.length; i++) {
                    if (elements[i].checked || elements[i].value != "") {
                        answers.push(elements[i].getAttribute("groupid") + ':' + elements[i].value);
                    }
                }
                if (username == "" || username == null) {
                    alert("联系人不能为空！");
                    return false;
                } else if (!username.match(/^[\u4e00-\u9fa5]{2,4}$/i)) {
                    alert('请输入正确的中文名');
                    return false;
                }
                if (phone == "" || phone == null) {
                    alert("联系电话不能为空！");
                    return false;
                } else if (!new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/).test(phone)) {
                    alert('手机格式不正确');
                    return false;
                }
                $.ajax({
                    url: "{:U('Order/add')}",
                    type: "POST",
                    async: false,
                    data: {
                        username: username,
                        phone: phone,
                        more: more,
                        bid: bid,
                        answers: answers
                    },
                    success: function (data) {
                        alert(data.info);
                        window.location.href = "{:U('Home')}";
                    }
                });
            })
        });
    </script>
</block>
